var app = getApp()
var host = app.data.host
var httpUtil = require("../utils/httpUtil.js")
var loginUtil=require("../utils/loginUtil.js")
var applyTuiUrl = host + "applyTui"
var getTuiUrl = host + "getTui"
var getTuiSettingUrl = host +"getTuiSetting"
var saveShareUrl=host+"saveShare"
var sumTuiAwardUrl = host +"sumTuiAward"
var tuiAwardUrl = host +"tuiAward"
var getApplyRecordUrl = host +"getApplyRecord"
var rewardApplyUrl = host +"rewardApply"
//成为推手
function applyTui(cb) {
  var data = {
    cusId: app.data.user.id
  }
  httpUtil.get(applyTuiUrl, data, cb)
}
//获取商品推销设置
function getTui(data, cb) {
  httpUtil.get(getTuiUrl, data, cb)
}
//分销系统设置
function getTuiSetting(cb){
  httpUtil.get(getTuiSettingUrl,null,cb)
}
//保存分享浏览记录
function saveShare(id,type,cusId,cb){
  var data={
    pid:id,
    type:type,
    shareCusId:cusId,
  }
  loginUtil.getOpenId(openid=>{
    data.receiverOpenid=openid
    httpUtil.post(saveShareUrl,data,cb)
  })
}
//分销奖励总额
function sumTuiAward(cb){
  var data={
    cusId:app.data.user.id
  }
  httpUtil.get(sumTuiAwardUrl,data,cb)
}
//分销奖励详情
function tuiAward(cb){
  var data = {
    cusId: app.data.user.id
  }
  httpUtil.get(tuiAwardUrl, data, cb)
}
//提现记录
function getApplyRecord(cb){
  var data={
    cusId:app.data.user.id
  }
  httpUtil.get(getApplyRecordUrl,data,cb)
}
//提现申请
function rewardApply(money,cb){
  var data = {
    cusId: app.data.user.id,
    money: money
  }
  httpUtil.get(rewardApplyUrl, data, cb)
}
module.exports = {
  applyTui: applyTui,
  getTui: getTui,
  getTuiSetting: getTuiSetting,
  saveShare: saveShare,
  sumTuiAward: sumTuiAward,
  tuiAward: tuiAward,
  getApplyRecord: getApplyRecord,
  rewardApply: rewardApply
}